home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / WANDR330.ZIP / SRC / ENCRYPT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-25  |  1.3 KB  |  60 lines

  1. #include "wand_head.h"
  2.  
  3. /* Uses seeded random xor to encrypt because setkey doesn't work on our
  4.    system. */
  5.  
  6. crypt_file(name)
  7. char *name;
  8. {
  9.     char buffer[1024];
  10.     int  fd, length, loop;
  11.  
  12. #ifdef TOS
  13.     if ((fd = open(name,O_RDONLY)) < 0) {
  14. #else
  15.     if ((fd = open(name,O_RDONLY)) == -1) {
  16. #endif
  17.     endwin();
  18.     sprintf(buffer,"Wanderer: cannot open %s",name);
  19.     perror(buffer);
  20.     exit(1);
  21.     }
  22.     if ((length = read(fd,buffer,1024)) < 1) {
  23.     endwin();
  24.     sprintf(buffer,"Wanderer: read error on %s",name);
  25.     perror(buffer);
  26.     exit(1);
  27.     }
  28.     close(fd);
  29.  
  30. /* Right, got it in here, now to encrypt the stuff */
  31.  
  32.     addstr("Running crypt routine....\n");
  33.     refresh();
  34.  
  35.     srand(BLURFL);
  36.     for (loop = 0; loop < length; loop++)
  37.     buffer[loop] ^= rand();
  38.  
  39. #ifdef TOS
  40.     if ((fd = open(name,O_WRONLY|O_TRUNC)) < 0) {
  41. #else
  42.     if ((fd = open(name,O_WRONLY|O_TRUNC)) == -1) {
  43. #endif
  44.     endwin();
  45.     sprintf(buffer,"Wanderer: cannot write to %s",name);
  46.     perror(buffer);
  47.     exit(1);
  48.     }
  49.     if (write(fd,buffer,length) != length) {
  50.     endwin();
  51.     sprintf(buffer,"Wanderer: write error on %s",name);
  52.     perror(buffer);
  53.     exit(1);
  54.     }
  55.     close(fd);
  56.  
  57. /* ok, file now contains encrypted/decrypted game. */
  58. /* lets go back home... */
  59. }
  60.